/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.cs.datasource.imap.ImapUtil;
/*     */ import com.zimbra.cs.mailclient.imap.ImapConfig;
/*     */ import com.zimbra.cs.mailclient.imap.ImapInputStream;
/*     */ import com.zimbra.cs.mailclient.imap.ListData;
/*     */ import com.zimbra.cs.mailclient.util.Ascii;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.IOException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Arrays;
/*     */ import java.util.List;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestImapUtil
/*     */   extends TestCase
/*     */ {
/*  33 */   private static final String[] FOLDERS = { "BOOBOO/BEAR", "INBOX", "Inbox", "Inbox/Foo", "Foobar", "INBOX/bar", "Foobar/Blah Blah/XXX", "foobar", "Foobar/Blah Blah" };
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*  38 */   private static final String[] FOLDERS_2 = { "Bulk Mail", "INBOX/Page-PSI-Wallet", "INBOX/ReviewBoard", "Trash", "INBOX/Page-PSI-Bill", "INBOX/QA", "INBOX/PSI-Wallet-OnCall", "INBOX/Devel-CPP", "INBOX/Manoj", "Drafts", "INBOX/PSI-Wallet", "INBOX/IT Support", "Sent", "INBOX/FitnessCenter", "INBOX/Hack", "INBOX/Bugzilla", "Junk E-mail", "Deleted Items", "Contacts", "Calendar", "INBOX/Devel-Random", "INBOX/PSI-Payments", "INBOX/D_PSI-Devel", "Sent Items", "INBOX/Page-PSI-Payments", "INBOX/BTN", "INBOX/PSI-Billing", "INBOX", "Outbox", "Journal", "Notes", "Tasks", "Sync Issues", "Sync Issues/Conflicts", "Sync Issues/Local Failures", "Sync Issues/Server Failures" };
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  77 */   private static final String[] SORTED_FOLDERS = { "INBOX", "INBOX/bar", "BOOBOO/BEAR", "Foobar", "Foobar/Blah Blah", "Foobar/Blah Blah/XXX", "Inbox", "Inbox/Foo", "foobar" };
/*     */   
/*     */ 
/*     */   public void testSortFolders()
/*     */     throws Exception
/*     */   {
/*  83 */     List<String> folders = getNames(ImapUtil.sortFolders(parseFolders(FOLDERS)));
/*  84 */     assertEquals(Arrays.asList(SORTED_FOLDERS), folders);
/*     */   }
/*     */   
/*     */   public void testSortFolders2() throws Exception {
/*  88 */     List<String> folders = getNames(ImapUtil.sortFolders(parseFolders(FOLDERS_2)));
/*  89 */     assertEquals("INBOX", (String)folders.get(0));
/*     */   }
/*     */   
/*     */   public void testUtf8Text() throws Exception {
/*  93 */     String msg = "UTF8: Àå";
/*  94 */     byte[] b = (msg + "\r\n").getBytes("UTF8");
/*  95 */     ImapInputStream is = new ImapInputStream(new ByteArrayInputStream(b), new ImapConfig());
/*  96 */     assertEquals(msg, is.readText());
/*  97 */     is.skipCRLF();
/*     */   }
/*     */   
/*     */   private void compareLists(List<?> expected, List<?> actual) {
/* 101 */     assertEquals(expected.size(), actual.size());
/* 102 */     for (int i = 0; i < expected.size(); i++) {
/* 103 */       assertEquals(expected.get(i), actual.get(i));
/*     */     }
/*     */   }
/*     */   
/*     */   private List<ListData> parseFolders(String[] folders) throws IOException {
/* 108 */     List<ListData> lds = new ArrayList();
/* 109 */     ImapInputStream is = getImapInputStream(folders);
/* 110 */     while (!is.isEOF()) {
/* 111 */       is.skipChar('*');
/* 112 */       is.skipChar(' ');
/* 113 */       is.readAtom();
/* 114 */       is.skipChar(' ');
/* 115 */       lds.add(ListData.read(is));
/* 116 */       is.skipCRLF();
/*     */     }
/* 118 */     return lds;
/*     */   }
/*     */   
/*     */   private List<String> getNames(List<ListData> lds) {
/* 122 */     List<String> names = new ArrayList(lds.size());
/* 123 */     for (ListData ld : lds) {
/* 124 */       names.add(ld.getMailbox());
/*     */     }
/* 126 */     return names;
/*     */   }
/*     */   
/*     */   private static ImapInputStream getImapInputStream(String[] folders) {
/* 130 */     StringBuilder sb = new StringBuilder();
/* 131 */     for (String folder : folders) {
/* 132 */       sb.append("* LIST () \"/\" \"").append(folder).append("\"\r\n");
/*     */     }
/* 134 */     ImapConfig config = new ImapConfig();
/* 135 */     return new ImapInputStream(new ByteArrayInputStream(Ascii.getBytes(sb.toString())), config);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestImapUtil.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */